﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ScriptCompare
{
    public abstract class LineCollectionBase : ILineCollection
    {
        protected readonly List<ScriptLine> _lines = new List<ScriptLine>();

        public LineCollectionBase(IEnumerable<ScriptLine> source)
        {
            if (source != null)
                _lines.AddRange(source);
        }

        #region ILineCollection Members

        public IList<ScriptLine> Lines
        {
            get { return (_lines); }
        }

        public IList<ScriptLine> GetComparableLines()
        {
            List<ScriptLine> compLines = new List<ScriptLine>();

            foreach (ScriptLine line in _lines)
            {
                if (!line.IsEmpty && !line.IsComment)
                {
                    compLines.Add(line);
                }
            }

            return (compLines);
        }

        public void ReplaceLines(IEnumerable<ScriptLine> source)
        {
            _lines.Clear();
            if (source != null)
                _lines.AddRange(source);
        }

        #endregion
    }
}
